

// BalanceInquiry.java
// Represents a balance inquiry ATM transaction

public class BalanceInquiry extends Transaction
{
   // BalanceInquiry constructor
   public BalanceInquiry( long userCpr, int userAccountNumber, Screen atmScreen, 
      BankDatabase atmBankDatabase )
   {
      super( userCpr, userAccountNumber, atmScreen, atmBankDatabase );
   } // end BalanceInquiry constructor

   // performs the transaction
   @Override
   public void execute()
   {
      // get references to bank database and screen
      BankDatabase bankDatabase = getBankDatabase();
      Screen screen = getScreen();

      // get the available balance for the account involved
      double availableBalance = 
         bankDatabase.getAvailableBalance( getCpr(), getAccountNumber() );

      // get the total balance for the account involved
      double totalBalance = 
         bankDatabase.getTotalBalance( getCpr(), getAccountNumber() );
      
      // display the balance information on the screen
      screen.displayMessageLine("\n+---------------------------------------+");
      screen.printHelper("Balance Information for " + bankDatabase.getCustomer(getCpr()).getAccount(getAccountNumber()).getType());
      //screen.displayMessageLine5("| - Available balance: " );
     
      String abal = String.format("$ %,.2f", availableBalance);
      screen.printHelper("- Available balance: "+abal);
      String abl = String.format("$ %,.2f",totalBalance);
      screen.printHelper("- Total balance:     "+abl);
      
      //screen.displayMessage2(abal);
      
      screen.displayMessageLine("|                                       |" );
      screen.displayMessageLine("+---------------------------------------+");
   } // end method execute
} // end class BalanceInquiry

